﻿using System;
using System.Collections.Generic;
using System.Text;
using Acms.WebControls;

namespace Acms.AcmsControls.ContentControls.FrontEnd
{
    /// <summary>
    /// Displays Flash video upload through the CMS
    /// </summary>
    public class FlashVideoContentControl : BaseContentControlDisplay<FlashVideoContentControlProperties>
    {
        public FlashVideoContentControl()
        {
            this.FlashControl = new FlashControl();
        }

        protected override void CreateChildControls()
        {
            this.Controls.Add(FlashControl);
            base.CreateChildControls();
        }

        public override bool IsEmpty
        {
            get 
            {
                return Properties == null || !Properties.HasResource();
            }
        }

        protected override void DataBindChildren()
        {
            if (!IsEmpty)
            {
                FlashControl.FlashFileUrl = Page.ResolveUrl(FlashPlayerUrl);
                FlashControl.Variables["videoUrl"] = Page.ResolveUrl(RenderFile.GetUrl(Properties.ResourceId, Page));
                FlashControl.Variables["videoSkinUrlStr"] = Page.ResolveUrl(FlashSkinUrl);
                FlashControl.Width = Width;
                FlashControl.Height = Height;
                FlashControl.MinVersion = "6.0.0.0";
                FlashControl.WMode = FlashControl.WModes.Transparent;
            }
        }

        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            //skip rendering control info
            RenderContents(writer);
        }

        /// <summary>
        /// Width for the flash movie
        /// </summary>
        public new int Width { get; set; }
        /// <summary>
        /// Height for the flash movie
        /// </summary>
        public new int Height { get; set; }
        /// <summary>
        /// Url for the flash player to load the flash video - the flash video as passed in as flash variable "videoUrl"
        /// </summary>
        public string FlashPlayerUrl { get; set; }
        /// <summary>
        /// Skin to load for the player. Added as a flash variable "videoSkinUrlStr"
        /// </summary>
        public string FlashSkinUrl { get; set; }

        public FlashControl FlashControl{get; private set;}

        public bool AllowFullScreen
        {
            get
            {
                return FlashControl.AllowFullScreen;
            }
            set
            {
                FlashControl.AllowFullScreen = value;
            }
        }
    }
}
